<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('合同流程审批')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="col-sm-8">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-sjcontract-add" th:object="${obj}">
    	<input name="id" type="hidden" th:field="*{id}" />
            <input name="ownerId" type="hidden" th:field="*{ownerId}" />
            <input name="deptId" type="hidden" th:field="*{deptId}" />
            <input type="hidden" id="approvename" name="approvename" th:value="${approvename}" />
        	<div class="form-group">    
               <label class="col-sm-2 control-label ">项目编号：</label>
               <div class="col-sm-4">
                   <input name="orderNo" th:field="*{orderNo}" class="form-control" type="text"  >
               </div>
               <label class="col-sm-2 control-label ">立项日期：</label>
               <div class="col-sm-4">
                    <div class="input-group date">
                        <input name="lxAt" class="form-control" th:value="${#dates.format(obj.lxAt, 'yyyy-MM-dd')}" placeholder="yyyy-MM-dd" type="text" >
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
           </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label is-required">建设单位：</label>
                <div class="col-sm-4">
                    <div class="input-group">
                    	<input id="customerName" th:value="*{customerName}" name="customerName" class="form-control" type="hidden">
                    	<input id="customerId" th:value="*{customerId}" name="customerId" class="form-control" type="hidden">
                    	<input class="form-control" type="text" onclick="selectCustomer()" th:value="*{customerName}" id="customerStr" readonly="true" required>
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
                </div>
<!-- 				<label class="col-sm-2 control-label ">投标关联：</label> -->
<!--                 <div class="col-sm-4"> -->
<!--                 	<select id="biddingId" th:field="*{biddingId}" name="bidding" class="form-control" > -->
<!--                 		<option value="" >空</option> -->
<!-- 						<option th:each="cl:${biddinglis}" th:value="${cl.id}" th:text="${cl.projectName}"></option> -->
<!-- 					</select> -->
<!--                 </div> -->
                <label class="col-sm-2 control-label is-required">项目名称：</label>
                <div class="col-sm-4">
                    <input name="name" th:field="*{name}" class="form-control" autoComplete="off" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label ">项目描述：</label>
                <div class="col-sm-10">
                    <textarea name="descs" class="form-control" >[[*{descs}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-2 control-label is-required">项目类型：</label>
                <div class="col-sm-4">
                    <select name="proType" th:field="*{proType}" class="form-control" th:with="type=${@dict.getType('sj_proType')}" required>
		                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
		            </select>
                </div>
                <label class="col-sm-2 control-label ">项目总金额：</label>
                <div class="col-sm-4">
                    <input name="zongje" th:field="*{zongje}" class="form-control" autoComplete="off" type="text" >
                </div> 
            </div>
            <div class="form-group"> 
            	<label class="col-sm-2 control-label ">项目管理费%：</label>
                <div class="col-sm-4">
                    <input name="glf" th:field="*{glf}" class="form-control" autoComplete="off" type="text" >
                </div> 
            	<label class="col-sm-2 control-label is-required">内审出图费用：</label>
                <div class="col-sm-4">
                    <select name="nsctType" th:field="*{nsctType}" class="form-control" th:with="type=${@dict.getType('sj_nsctfy')}" required>
		                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
		            </select>
                </div>
            </div>
            <div class="form-group"> 
            	<label class="col-sm-2 control-label ">建设单位联系人：</label>
                <div class="col-sm-4">
                    <input name="customerPerson" th:field="*{customerPerson}" class="form-control" autoComplete="off" type="text" >
                </div> 
                <label class="col-sm-2 control-label ">建设单位联系电话：</label>
                <div class="col-sm-4">
                    <input name="customerPhone" th:field="*{customerPhone}" class="form-control" autoComplete="off" type="text" >
                </div>
            </div>
            <div class="form-group"> 
            	<label class="col-sm-2 control-label is-required">是否外包：</label>
                <div class="col-sm-4">
                    <select id="isWb" name="isWb" th:field="*{isWb}" class="form-control" required>
						<option value="0">否</option>
						<option value="1">是</option>
					</select>
                </div>
                <label class="col-sm-2 control-label ">外包内容：</label>
                <div class="col-sm-4">
                    <input name="wbDescs" th:field="*{wbDescs}" class="form-control" autoComplete="off" type="text" >
                </div>
            </div>
            <div class="form-group"> 
            	<label class="col-sm-2 control-label ">项目面积：</label>
                <div class="col-sm-4">
                    <input name="mianji" th:field="*{mianji}" class="form-control" autoComplete="off" type="text" >
                </div> 
                <label class="col-sm-2 control-label is-required">项目负责人：</label>
                <div class="col-sm-4">
                	<div class="input-group">
                    	<input id="proFzr" th:value="*{proFzr}" name="proFzr" class="form-control" type="hidden">
                    	<input id="proFzrId" th:value="*{proFzrId}" name="proFzrId" class="form-control" type="hidden">
                    	<input class="form-control" type="text" onclick="selectproFzr()" id="proFzrStr" th:value="*{proFzr}" readonly="true" required>
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
                </div>
            </div>
            <div class="form-group">  
            	<label class="col-sm-2 control-label is-required">项目董事：</label>
                <div class="col-sm-4">
                	<div class="input-group">
                    	<input id="proDsz" th:value="*{proDsz}" name="proDsz" class="form-control" type="hidden">
                    	<input id="proDszId" th:value="*{proDszId}" name="proDszId" class="form-control" type="hidden">
                    	<input class="form-control" type="text" onclick="selectproDsz()" id="proDszStr" th:value="*{proDsz}" readonly="true" required>
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
                </div>
                <label class="col-sm-2 control-label is-required">商务经理：</label>
                <div class="col-sm-4">
                    <input name="proSwjl" th:field="*{proSwjl}" class="form-control" readonly="readonly" autoComplete="off" type="text" required >
                    <input name="proSwjlId" th:field="*{proSwjlId}" type="hidden" >
                </div>
            </div>
            <div class="form-group">  
            	<label class="col-sm-2 control-label is-required">方案主创：</label>
                <div class="col-sm-4">
                	<div class="input-group">
                    	<input id="proFazc" name="proFazc" th:value="*{proFazc}" class="form-control" type="hidden">
                    	<input id="proFazcId" name="proFazcId" th:value="*{proFazcId}" class="form-control" type="hidden">
                    	<input class="form-control" type="text" onclick="selectproFazc()" th:value="*{proFazc}" id="proFazcStr" readonly="true" required>
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
                </div>
                <label class="col-sm-2 control-label is-required">项目所属：</label>
                <div class="col-sm-4">
                    <select name="authority" th:field="*{authority}" class="form-control" required>
						<option th:each="cl:${deptlis}" th:value="${cl.deptId}" th:text="${cl.deptName}"></option>
					</select>
                </div> 
            </div>
            <div class="form-group">  
            	<label class="col-sm-2 control-label ">成本经理：</label>
                <div class="col-sm-4">
                	<div class="input-group">
                    	<input id="cbjl" name="cbjl" th:value="*{cbjl}" class="form-control" type="hidden">
                    	<input id="cbjlId" name="cbjlId" th:value="*{cbjlId}" class="form-control" type="hidden">
                    	<input class="form-control" type="text" onclick="selectcbjl()" th:value="*{cbjl}" id="cbjlStr" readonly="true" >
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
                </div>
                <label class="col-sm-2 control-label ">市场专员：</label>
                <div class="col-sm-4">
                	<div class="input-group">
                    	<input id="sczy" name="sczy" th:value="*{sczy}" class="form-control" type="hidden">
                    	<input id="sczyId" name="sczyId" th:value="*{sczyId}" class="form-control" type="hidden">
                    	<input class="form-control" type="text" onclick="selectsczy()" th:value="*{sczy}" id="sczyStr" readonly="true" >
						<span class="input-group-addon"><i class="fa fa-search"></i></span>
					</div>
                </div>
            </div>
            <div class="form-group"> 
            	<label class="col-sm-2 control-label ">项目年份：</label>
                <div class="col-sm-4">
                	<select name="yearStr" th:field="*{yearStr}" class="form-control" th:with="type=${@dict.getType('sj_yearStr')}" >
		                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
		            </select>
                </div>
                <label class="col-sm-2 control-label is-required">主体公司：</label>
            	<div class="col-sm-4">
            		<select name="ztdw" th:field="*{ztdw}" class="form-control" th:with="type=${@dict.getType('sj_gongs')}">
                    	<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                	</select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label ">备注：</label>
                <div class="col-sm-10">
                    <textarea name="memo" class="form-control" >[[*{memo}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
	                <label class="col-sm-2 control-label is-required">申请人：</label>
	                <div class="col-sm-4">
	                    <input name="owner" class="form-control" th:field="*{owner}" type="text" readonly="readonly" required/>
	                </div>
	                <label class="col-sm-2 control-label is-required">申请部门：</label>
	                <div class="col-sm-4">
	                    <input name="dept" class="form-control" th:field="*{dept}" type="text" readonly="readonly" required/>
	                </div>
	            </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">是否重新申请：</label>
            <div class="col-sm-4">
                <label class="radio-box">
                    <input type="radio" checked="" value="true" name="userapprove">是</label>
                <label class="radio-box">
                    <input type="radio" value="false" name="userapprove">否</label>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-3 col-sm-offset-3">
                <input type="hidden"  name="taskid" id="taskid" th:value="${taskid}">
                <input type="hidden"  name="id" id="id" th:value="${obj.id}">
                <input type="hidden"  name="status" id="status" th:value="1">
                <button class="btn btn-primary" onclick="submitHandler()" type="button"><i class="fa fa-check"></i>&nbsp;提交</button>
            </div>
        </div>
    </form>
</div>
</div>
<div id="ibox-content" class="col-sm-4">
    <div id="vertical-timeline" class="vertical-container dark-timeline">
    </div>
</div>
</body>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefix = ctx + "task/manage"
    $("#form-sjcontract-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        var taskid = $("#taskid").val();
        var userapprove = document.querySelector("input[name='userapprove']:checked").value;
        
        if(userapprove=="false"){
            $("#status").val(4);
        }else{
            $("#status").val(2);
        }
        
        $.operate.save("edit4check", $('#form-sjcontract-add').serialize(), function(){
            var json = {"userapprove": userapprove};
            $.ajax({
                url : prefix + "/completeTask/" + taskid,
                type : "POST",
                data : JSON.stringify(json), //转JSON字符串
                dataType: 'json',
                contentType:'application/json;charset=UTF-8', //contentType很重要
                success : function(result) {
                    $.modal.msg("办理成功");
//                     const parent = window.parent;
//                     // 我的待办
//                     const myToDoIframe = parent.document.querySelector("iframe[src='/task/manage/mytask']");
//                     // 我的全部待办
//                     const myAllToDoIframe = parent.document.querySelector("iframe[src='/task/manage/alltasks']");
//                     myToDoIframe && myToDoIframe.contentWindow.location.reload(true);
//                     myAllToDoIframe && myAllToDoIframe.contentWindow.location.reload(true);
//                     $.modal.closeTab();
                }
            });
        });
    }

    $(document).ready(function(){
        // 获取时间轴
        $.get(prefix + "/history/" + $("#taskid").val(), function(data){
            for (var a = 0; a < data.length ; a++) {
                $("#vertical-timeline").append("<div class=\"vertical-timeline-block\"><div class=\"vertical-timeline-icon lazur-bg\">" +
                    "<i class=\"fa fa-briefcase\"></i></div>" +
                    "<div class=\"vertical-timeline-content\">" +
                    "<span class=\"vertical-date\">开始 <small>" + data[a].startTime + "</small></span><br>" +
                    "<h2><b>" + data[a].assignee + ":</b>" + data[a].taskName + "</h2>" +
                    "<p>" + (data[a].comment || "-") + "</p>" +
                    "<span class=\"vertical-date\">结束 <small>" + (data[a].endTime || "-") + "</small></span>" +
                    "</div>" +
                    "</div>");
            }
        });
    });
    
    $(function() {
		var zilwj = $("#zilwjvo").val();
    	
    	var n=zilwj.split(",");
    	for(var i=0;i<n.length;i++){
//     		var url = "http://lkgnews.cn:8012/onlinePreview?url="+encodeURIComponent(Base64.encode(n[i]));
    		var url = n[i];
    		$("#zlwjlink").append("<a href='"+url+"' target='_blank' >"+n[i]+"</a><br>");
    	}
    	
    });
    
  //选择用户selectproFzr
	function selectproFzr() {
		var options = {
	       title: '选择用户',
	       url: "/sj/config/invokeUser",
	       width: '1000',
	       height: '670',
	       callBack: doSubmitlevel1User
	    };
	    $.modal.openOptions(options);
	}
 	
	function doSubmitlevel1User(index, layero){
        var rows = layero.find("iframe")[0].contentWindow.getSelections();
        if (rows.length == 0) {
            $.modal.alertWarning("请选择一条记录！");
            return;
        }
        
        if (rows.length > 1) {
            $.modal.alertWarning("请勿选择多条记录！");
            return;
        }
        
        $("#proFzrId").val(rows[0].userId);
        $("#proFzr").val(rows[0].userName);
        $("#proFzrStr").val(rows[0].userName);
        $.modal.closeAll();
    }
	
	//选择用户selectproDsz
	function selectproDsz() {
		var options = {
	       title: '选择用户',
	       url: "/sj/config/invokeUser",
	       width: '1000',
	       height: '670',
	       callBack: doSubmitlevel2User
	    };
	    $.modal.openOptions(options);
	}
 	
	function doSubmitlevel2User(index, layero){
        var rows = layero.find("iframe")[0].contentWindow.getSelections();
        if (rows.length == 0) {
            $.modal.alertWarning("请选择一条记录！");
            return;
        }
        
        if (rows.length > 1) {
            $.modal.alertWarning("请勿选择多条记录！");
            return;
        }
        
        $("#proDszId").val(rows[0].userId);
        $("#proDsz").val(rows[0].userName);
        $("#proDszStr").val(rows[0].userName);
        $.modal.closeAll();
    }
	
	//选择用户selectproFazc
	function selectproFazc() {
		var options = {
	       title: '选择用户',
	       url: "/sj/config/invokeUser",
	       width: '1000',
	       height: '670',
	       callBack: doSubmitlevel3User
	    };
	    $.modal.openOptions(options);
	}
 	
	function doSubmitlevel3User(index, layero){
        var rows = layero.find("iframe")[0].contentWindow.getSelections();
        if (rows.length == 0) {
            $.modal.alertWarning("请选择一条记录！");
            return;
        }
        
        if (rows.length > 1) {
            $.modal.alertWarning("请勿选择多条记录！");
            return;
        }
        
        $("#proFazcId").val(rows[0].userId);
        $("#proFazc").val(rows[0].userName);
        $("#proFazcStr").val(rows[0].userName);
        $.modal.closeAll();
    }
	
	//选择用户selectcbjl
	function selectcbjl() {
		var options = {
	       title: '选择用户',
	       url: "/sj/config/invokeUser",
	       width: '1000',
	       height: '670',
	       callBack: doSubmitlevel4User
	    };
	    $.modal.openOptions(options);
	}
 	
	function doSubmitlevel4User(index, layero){
        var rows = layero.find("iframe")[0].contentWindow.getSelections();
        if (rows.length == 0) {
            $.modal.alertWarning("请选择一条记录！");
            return;
        }
        
        if (rows.length > 1) {
            $.modal.alertWarning("请勿选择多条记录！");
            return;
        }
        
        $("#cbjlId").val(rows[0].userId);
        $("#cbjl").val(rows[0].userName);
        $("#cbjlStr").val(rows[0].userName);
        $.modal.closeAll();
    }
	
	//选择用户selectsczy
	function selectsczy() {
		var options = {
	       title: '选择用户',
	       url: "/sj/config/invokeUser",
	       width: '1000',
	       height: '670',
	       callBack: doSubmitlevel5User
	    };
	    $.modal.openOptions(options);
	}
 	
	function doSubmitlevel5User(index, layero){
        var rows = layero.find("iframe")[0].contentWindow.getSelections();
        if (rows.length == 0) {
            $.modal.alertWarning("请选择一条记录！");
            return;
        }
        
        if (rows.length > 1) {
            $.modal.alertWarning("请勿选择多条记录！");
            return;
        }
        
        $("#sczyId").val(rows[0].userId);
        $("#sczy").val(rows[0].userName);
        $("#sczyStr").val(rows[0].userName);
        $.modal.closeAll();
    }
	
	//选择用户selectproSwjl
	function selectproSwjl() {
		var options = {
	       title: '选择用户',
	       url: "/sj/config/invokeUser",
	       width: '1000',
	       height: '670',
	       callBack: doSubmitlevel6User
	    };
	    $.modal.openOptions(options);
	}
 	
	function doSubmitlevel6User(index, layero){
        var rows = layero.find("iframe")[0].contentWindow.getSelections();
        if (rows.length == 0) {
            $.modal.alertWarning("请选择一条记录！");
            return;
        }
        
        if (rows.length > 1) {
            $.modal.alertWarning("请勿选择多条记录！");
            return;
        }
        
        $("#proSwjlId").val(rows[0].userId);
        $("#proSwjl").val(rows[0].userName);
        $("#proSwjlStr").val(rows[0].userName);
        $.modal.closeAll();
    }
	
	$("input[name='lxAt']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });
    
  //选择用户selectCustomer
	function selectCustomer() {
		var options = {
	       title: '合作联系人',
	       url: "/gcgl/customer/invokeCustomer",
	       width: '1000',
	       height: '670',
	       callBack: doSubmitCustomer
	    };
	    $.modal.openOptions(options);
	}
 	
	function doSubmitCustomer(index, layero){
        var rows = layero.find("iframe")[0].contentWindow.getSelections();
        if (rows.length == 0) {
            $.modal.alertWarning("请选择一条记录！");
            return;
        }
        
        if (rows.length > 1) {
            $.modal.alertWarning("请勿选择多条记录！");
            return;
        }
        
        $("#customerId").val(rows[0].id);
        $("#customerName").val(rows[0].ckdw);
        $("#customerStr").val(rows[0].ckdw);
        $.modal.closeAll();
    }
</script>
</body>
</html>